import 'package:flutter/material.dart';
import 'package:bear_story/views.dart';
import '../net.dart' as net;
import '../bean/beans.dart';
import '../page/book.dart';
import '../main.dart';

class ChildSongTabView extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return ChildSongState();
  }
}

class ChildSongState extends State<ChildSongTabView> with AutomaticKeepAliveClientMixin {
  List<Book> books = [];
  int count = 10;
  ScrollController scrollController = ScrollController();

  @override
  void initState() {
    super.initState();
    scrollController.addListener(() {
      if (scrollController.offset == scrollController.position.maxScrollExtent) {
//        print('滑动到了最底部');
//        loadMore();
      }
    });
    refresh();
  }

  Future loadMore() async {
    await Future.delayed(Duration(seconds: 3), () {
      setState(() {});
    });
    return null;
  }

  Future refresh() async {
    var list = await net.getBookByClassify("KOkCwwwD");
    if (list != null) {
      books = list;
      refreshBookExtraInfo(books).then((v) {
        setState(() {});
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    super.build(context);
    return Container(
      padding: EdgeInsets.only(top: 0, bottom: play_controller_bar_height),
      color: background_color,
      child: ListView.builder(
        padding: EdgeInsets.only(top: 14),
        controller: scrollController,
        itemBuilder: (context, index) {
          var book = books[index];
          return AlbumListItemView(book);
        },
        itemCount: books.length,
      ),
    );
  }

//  @override
//  Widget build(BuildContext context) {
//    // TODO: implement build
//    super.build(context);
//    return RefreshIndicator(
//        color: main_theme_color,
//        onRefresh: refresh,
//        child: Container(
//          padding: EdgeInsets.only(top: 0, bottom: play_controller_bar_height),
//          color: background_color,
//          child: ListView.builder(
//            padding: EdgeInsets.only(top: 14),
//            controller: scrollController,
//            itemBuilder: (context, index) {
//              var book = books[index];
//              return AlbumListItemView(book);
//            },
//            itemCount: books.length,
//          ),
//        ));
//  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
